﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Data;


namespace document_manage
{
    class MySQLConn
    {
        private string MysqlCon = "Database=document_manage; Data Source=localhost;User Id=root;"
            + "Password=123456;pooling = false; CharSet = utf8 ;port =3306";
        public DataTable ExecuteQuery(string sqlStr)
        {
            MySqlCommand cmd;
            MySqlConnection con;
            MySqlDataAdapter msda;//数据适配器，DataAdapter对象在DataSet与数据之间起桥梁作用
            con = new MySqlConnection(MysqlCon);
            con.Open();
            cmd = new MySqlCommand(sqlStr, con);
            cmd.CommandType = CommandType.Text;
            DataTable dt = new DataTable();
            msda = new MySqlDataAdapter(cmd);
            msda.Fill(dt);
            con.Close();
            return dt;
        }

        public int ExecuteUpdate(string sqlStr)
        {
            int iud = 0;
            MySqlCommand cmd;
            MySqlConnection con;
            con = new MySqlConnection(MysqlCon);
            con.Open();
            cmd = new MySqlCommand(sqlStr, con);
            cmd.CommandType = CommandType.Text;
            iud = cmd.ExecuteNonQuery();
            con.Close();
            return iud;
        }

    }
}
